package com.sohoometer.base.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

@Repository("baseDao")
public class BaseDaoImpl extends JdbcTemplate implements BaseDao {
	@Autowired
	public BaseDaoImpl(DataSource dataSource) {
		setDataSource(dataSource);
	}
	@Override
	public Map<String, String> queryIdMap(){
		String sql = "(SELECT ID AS id,t_project_name  AS NAME FROM  base_project_info) UNION(SELECT	 ID AS id,	t_comm_name  AS   NAME FROM	base_community_info) UNION(SELECT	ID AS id,	t_building_name AS NAME FROM	base_building_info)";
		Map<String, String> map = new HashMap<String, String>();
		List<Map<String,Object>> queryForList = queryForList(sql);
		for(Map<String, Object> maps:queryForList) {
			map.put((String) maps.get("id"),(String) maps.get("NAME"));
		}
		return map;
	}
}
